When you populate a field on an Xpage programmatically (i.e through an onclick event of a button), you will need to directly update the datasource field on the back-end in order to keep the two values in sync. The reason for doing this is because the JSP lifecycle updates the back-end datasource document before updating the Xpage UI element. For more information on the JSP lifecycle click
HERE.
For a simple example of this follow these steps:
1. Create a new form in a Notes database with two text fields. Then create a view with two columns showing the two text fields.
2. Create a new Xpage and bind a datasource document to the Form you just created. Use 'Open document' as the default action.
3. Drag two Edit Boxes and bind each one to one of fields on the datasource you just created. You can set the data type that you want. For this example, I used the following properties:
4. Then create a button and go to the Events tab and add an 'execute script' action and a 'save document' action after that. Enter the following code into the script action:
getComponent("inputText1").setValue(@Now());
If you have set it up the same as I have, this will grab the current system clock value and set it to the edit box called inputText1. You should have something like this:
5. Now preview the Xpage in a browser and enter a sample text in the second edit box the press the button. You should see the first edit box populate with the current date/time. If you look at the back-end form document however you will see that the field pertaining to the first edit box is blank and the second one contains your sample text that you entered on the browser before clicking the button. This shows you that the back-end is first updated with what is contained in the Xpage fields before executing the scripts to update/populate the Xpage.
If you wanted to keep the two in sync, then you can use the following code instead which will directly set the back-end field.
getComponent("inputText1").setValue(@Now());
document1.setValue("CurrentTime", getComponent("inputText1").getValue())
This sets the value as before, but then grabs that value and sets it to the back-end field as well.